1. Field of the Invention
This invention relates to source converter processing methods that perform conversion of source programs containing language statements for accessing memories. In addition, this invention also relates to machine-readable media that store programs of the source converter processing methods.
This application is based on Patent Application No. Hei 10-19991 filed in Japan, the content of which is incorporated herein by reference.
2. Description of the Related Art
Conventionally, source converters are provided to convert source programs to other computer languages, so that source converter processing methods are provided for processing of the source converters.
For example, the paper of Japanese Patent Application, Publication No. Hei 3-252819 discloses an example of the device for converting the assembler source program to COBOL source program (where xe2x80x9cCOBOLxe2x80x9d is an acronym for xe2x80x9cCommon Business Oriented Languagexe2x80x9d). Herein, the source program conversion is effected using operands between the assembler source program and COBOL source program, but it is not always applicable to the high level programming language such as the C language used for the Unix system, for example.
FIG. 7 and FIG. 8 are flowcharts showing an example of the source converter processing method.
FIG. 9 shows an example of statements written in an assembly language for a 4-bit microcomputer, which is subjected to conversion using the source converter. FIG. 10 shows an example of a symbol table that is created by the source converter when the assembly language is converted to C language. FIG. 11 shows an example of statements written in the C language, which are obtained by converting statements of the assembly language of FIG. 9 by the source converter. In the statements, xe2x80x9cNIBBLExe2x80x9d represents a unit of information used in the 4-bit microcomputer. That is, it represents an amount of information having a half of byte. In addition, a symbol xe2x80x9cHxe2x80x9d following numeric symbols representing an address indicate that the numeric symbols are represented in hexadecimal notation.
In the flowchart of FIG. 7, a reference symbol xe2x80x9cS1xe2x80x9d designates a statement analysis step that performs analysis of statements, while xe2x80x9cS2xe2x80x9d designates a symbol definition decision step for making a decision as to whether an input statement corresponds to a statement of symbol definition or not. In addition, a reference symbol xe2x80x9cS3xe2x80x9d designates a symbol name registration step that detects a symbol name of a definition symbol from the statement of the symbol definition so as to register it with the symbol table, while xe2x80x9cS4xe2x80x9d designates a symbol size registration step that detects a size of the definition symbol from the statement of the symbol definition so as to register it with the symbol table. xe2x80x9cS6xe2x80x9d designates a symbol conversion step that performs conversion to statements of symbol definition of the C language in accordance with content of the symbol table and prescribed conversion method. xe2x80x9cS7xe2x80x9d designates an out-of-symbol-definition-statement processing step that deals with statements of out-of-symbol-definition that are out of the statements of the symbol definition determined by the symbol definition decision step S2. That is, the step S7 performs analysis on statements of such out-of-symbol-definition so as to perform processing required for conversion on the basis of analysis result. xe2x80x9cS8xe2x80x9d designates an out-of-symbol-definition-statement conversion step that converts statements of the out-of-symbol-definition to statements of the C language. xe2x80x9cS9xe2x80x9d designates a statement end decision step that makes a decision as to whether the input statement ends or not. Moreover, a reference symbol xe2x80x9c50xe2x80x9d designates a symbol table that stores symbols and their sizes.
FIG. 8 shows details of the aforementioned out-of-symbol-definition-statement processing step S7 shown in FIG. 7. In FIG. 8, a reference symbol xe2x80x9cS11xe2x80x9d designates a memory access decision step for making a decision as to whether an input statement corresponds to a statement of memory access or not, while xe2x80x9cS12xe2x80x9d designates a symbol reference decision step for making a decision as to whether the input statement corresponds to a statement of symbol reference or not. xe2x80x9cS13xe2x80x9d designates a symbol name analysis step for performing analysis on the statement of the symbol reference to detect a name of a reference symbol, while xe2x80x9cS14xe2x80x9d designates a symbol search step that extracts the reference symbol from the symbol table 50 on the basis of the name of the reference symbol. xe2x80x9cS51xe2x80x9d designates a reference address statement creation step that creates statements of C language on the basis of definition size of the reference symbol, which is detected from a column of xe2x80x9cdefinition sizexe2x80x9d of the symbol table 50, as well as an address of a memory to be referred to. xe2x80x9cS21xe2x80x9d designates a constant reference address analysis step that performs analysis on the address of the memory referred in the statement of out-of-symbol-reference which is discriminated to be different from the statement of the symbol reference in step S12. xe2x80x9cS52xe2x80x9d designates a reference address communication step that communicates a reference address in the statement of the out-of-symbol-reference. xe2x80x9cS20xe2x80x9d designates an out-of-subject-statement processing step that performs processing required for conversion in response to analysis result with respect to statements of out-of-memory-access which are discriminated to be different from statements of memory access.
With reference to FIG. 7 and FIG. 8, operations of the steps will be described in detail. For example, the statement analysis step S1 inputs a statement of the assembly language which describes xe2x80x9cMEMORY NIBBLE 00H. 12Hxe2x80x9d. In order to confirm description of the input statement, a decision is made as to whether the input statement is registered as reserved words which are reserved in advance or not, or whether the input statement is registered with the symbol table 50. If the input statement is registered, a type of the input statement is expressed using a type of the corresponding reserved word(s) or a type of the corresponding information stored in the symbol table 50. If analysis result indicates that the input statement is not registered, it is detected that the input statement corresponds to error, which forms a statement description error.
Next, in step S2, a decision is made as to whether the input statement analyzed in step S1 is a statement of symbol definition or not. In this case, the input statement includes xe2x80x9cNIBBLExe2x80x9d defining a size of a symbol, which coincides with the reserved word. So, the step S2 determines that the input statement corresponds to the statement of the symbol definition. Then, the symbol name registration step S3 extracts a symbol name of xe2x80x9cMEMORYxe2x80x9d of the definition symbol from the input statement written in the assembly language, so that the step S3 registers it in a column of xe2x80x9csymbol namexe2x80x9d of the symbol table 50. In addition, the symbol size registration step S4 registers xe2x80x9cNIBBLExe2x80x9d representing the size of the definition symbol in a column of xe2x80x9cdefinition sizexe2x80x9d of the symbol table 50. As a result, the symbol table 50 stores xe2x80x9cMEMORYxe2x80x9d as the symbol name and xe2x80x9cNIBBLExe2x80x9d as the definition size, which is shown in FIG. 10.
Incidentally, a constant is set to an address designating a memory used for the input statement of the assembly language of xe2x80x9cMEMORY NIBBLE 00H. 12Hxe2x80x9d. For this reason, it is impossible to convert the aforementioned input statement of the assembly language to the statement of the symbol definition written in the C language. Thus, error occurs in the symbol conversion step S6.
Next, the step S1 analyzes a statement of the assembly language that describes xe2x80x9cMOV MEMORY+1, #0FHxe2x80x9d. This statement does not coincide with the reserved word(s) of the symbol definition which is registered in advance. Thus, the symbol definition decision step S2 determines that this statement does not correspond to the statement of the symbol definition. So, the system of the source converter processing method transfer control to step S7. The out-of-symbol-definition-statement processing step S7 performs predetermined processing on the aforementioned statement, which is determined to be different from the statement of the symbol definition, in response to analysis result. Then, the out-of-symbol-definition-statement conversion step S8 converts it to a statement of the C language suited to the processing of the out-of-symbol-definition-statement processing step S7.
Next, a description will be given with respect to detailed operations of the out-of-symbol-definition-statement processing step S7 with reference to FIG. 8. Herein, the step S deals with the aforementioned statement of the assembly language which describes xe2x80x9cMOV MEMORY+1, #0FHxe2x80x9d and which is determined to be different from the statement of the symbol definition. The memory access decision step S11 determines that xe2x80x9cMOVxe2x80x9d in the statement of the assembly language coincides with the reserved word which is registered in advance to represent an instruction for performing memory access. That is, the step S11 determines the statement as a statement of memory access. Then, the symbol reference decision step S12 determines the statement as a statement of symbol reference because the statement includes xe2x80x9cMEMORY+1xe2x80x9d. Next, the symbol name analysis step S13 detects a name of a reference symbol, i.e., xe2x80x9cMEMORYxe2x80x9d. The symbol search step S14 detects definition size of xe2x80x9cNIBBLExe2x80x9d of the reference symbol xe2x80x9cMEMORYxe2x80x9d with reference to the symbol table 50. At this time, the symbol table 50 stores content shown in FIG. 10. Next, the reference address statement creation step S51 creates statements of the C language for producing a reference address on the basis of the definition size of xe2x80x9cNIBBLExe2x80x9d and xe2x80x9cMEMORY+1xe2x80x9d. Specifically, it creates a statement for setting a pointer that describes xe2x80x9cstatic nibble MEMORY_P;xe2x80x9d, a statement for setting the pointer that describes xe2x80x9cMEMORY_P=andMEMORY;xe2x80x9d and a statement for reference of the pointer that describes xe2x80x9c*(MEMORY_P+1)=0xF;xe2x80x9d. Thereafter, the system transfers control to step S8 shown in FIG. 7. So, the out-of-symbol-definition-statement conversion step S8 converts them to statements of the C language.
Next, the memory access decision step S11 inputs a statement of the assembly language that describes xe2x80x9cMOV MEMORY, #05Hxe2x80x9d. The step S11 determines the statement as a statement of memory access because xe2x80x9cMOVxe2x80x9d contained in the statement coincides with the reserved word representing an instruction for performing memory access. The symbol reference decision step S12 determines the statement as a statement of a symbol reference because the statement includes xe2x80x9cMEMORYxe2x80x9d. The symbol name analysis step S13 detects a name of the reference symbol of xe2x80x9cMEMORYxe2x80x9d. The symbol search step S14 detects definition size of xe2x80x9cNIBBLExe2x80x9d of the reference symbol of xe2x80x9cMEMORYxe2x80x9d with reference to the symbol table 50. The reference address statement creation step S51 creates a statement of the C language for producing a reference address on the basis of the definition size of xe2x80x9cNIBBLExe2x80x9d and xe2x80x9cMEMORYxe2x80x9d. Namely, the step S51 creates a statement for reference of a pointer that describes xe2x80x9cMEMORY_P=0x5;xe2x80x9d. Next, the out-of-symbol-definition-statement conversion step S8 (see FIG. 7) converts it to a statement of the C language.
Next, the memory access decision step S11 inputs a statement of the assembly language that describes xe2x80x9cADD 0H, MEMORYxe2x80x9d. Herein, xe2x80x9cADDxe2x80x9d coincides with the reserved word representing an instruction for performing memory access, so the step S11 determines the statement as a statement of memory access. In addition, xe2x80x9c0Hxe2x80x9d does not represent a symbol but a constant, so the symbol reference decision step S12 determines the statement to be different from a statement of symbol reference. So, the system transfers control to step S21. The constant reference address analysis step S21 produces a reference address of xe2x80x9c00H. 00Hxe2x80x9d based on xe2x80x9c0Hxe2x80x9d of the statement. Such a constant address cannot be converted to a statement of the C language. So, the reference address communication step S52 communicates the reference address of xe2x80x9c00H. 00Hxe2x80x9d as an error message. In this case, the system skips the out-of-symbol-definition-statement conversion step S8 shown in FIG. 7.
The aforementioned steps are repeated until the statement end decision step S9 shown in FIG. 7 detects that no further statement is input.
By performing the aforementioned steps, the statements of the assembly language shown in FIG. 9 are converted to the statements of the C language shown in FIG. 11.
However, the aforementioned source converter processing method as shown in FIG. 7 and FIG. 8 suffers from a variety of problems, which will be described below.
In the case where the assembly language which is a low-level language is converted to the C language which is a high-level language, the source converter processing method does not have a capability of converting statements of symbol definition, which are written in the assembly language and whose absolute addresses are designated, to statements of the C language. For this reason, corrections should be required for the source program of the C language after the conversion.
In addition, the aforementioned source converter processing method does not have a capability of converting statements of the assembly language, in which addresses are not designated using symbols but are designated using constants, to statements of the C language. Thus, the method requires corrections on the source program of the C language after the conversion.
Further, in the case where conversion is performed on statements of the assembly language that is designed to perform memory access by designating relative addresses of symbols, the aforementioned source converter processing method converts them to statements of the C language without securing consecutive memory areas. For this reason, when the source program after the conversion is complied and is then executed, there occur incorrect operations.
It is an object of the invention to provide a source converter processing method that is capable of performing conversion on statements of symbol definition using absolute addresses and statements of address designation using constants.
It is another object of the invention to provide a source converter processing method that is capable of converting statements of memory access designating relative addresses to statements that do not cause incorrect operations when executing source programs after compilation.
It is a further object of the invention to provide machine-readable media storing the source converter processing method.
A source converter processing method of this invention is designed to have a capability of converting statements of symbol definition designating absolute addresses and statements of address designation using constants, both of which are written in assembly languages.
With regard to the statement of symbol definition written in the assembly language, the method analyzes it to detect the symbol definition, information (i.e., name, definition size and definition address) of which is registered with a symbol table. Then, the registered content of the symbol table is converted to the statements of the C language, for example.
With regard to the out-of-symbol-definition-statement, the method detects a reference symbol in connection with memory operation. Then, the method produces a reference address and a terminal address based on information regarding the reference symbol with reference to the symbol table. So, the method creates a new symbol based on the reference address and terminal address, so that information regarding the new symbol is registered with the symbol table. Further, with reference to a conversion table that stores information regarding the memory operation and the reference address, the method determines whether to enable consecutive statement conversion or single statement conversion, by which the statements of the assembly language are converted to the statements of the C language in an appropriate manner.
Incidentally, it is possible to store programs and data regarding the source converter processing method on recording media.